<template>
  <div>
    <Top title="设置" iconShow="1"></Top>
    <div class="setting">
      <div class="setting-item" v-for="(item,index) in dataList" :key="index" @click="goPage(item.url)">
        <span><img :src="item.imgUrl" /></span>
        <div>{{item.name}}</div>
        <i class="iconfont icon-jiankuohaoxiyou"></i>
      </div>
      <div class="setting-outlogin" @click="outLogin">退出登录</div>
    </div>

  </div>
</template>
<script>
import Top from '../components/Header';
import { MessageBox } from 'mint-ui';
import { cookie } from 'vux';
export default {
  name: 'login',
  data() {
    return {
      dataList: [{
        imgUrl: "static/img/xiugaimima.png",
        name: "修改密码",
        url: '/setting/modifypassword'
      },
      {
        imgUrl: "static/img/guanyuwomen.png",
        name: "关于我们",
        url: '/setting/aboutus'
      },
      {
        imgUrl: "static/img/fankui.png",
        name: "去反馈",
        url: '/setting/feedback'
      }]
    }
  },
  mounted(){
    document.setTitle('设置');
  },
  methods: {
    outLogin() {
      var token = cookie.get('token');
      var postData = {token:token};
      // 调用退出登录接口
      this.$http.post("/loansupermarket-app/user/loginOut",postData)
        .then((response) => {
          var resBody = response.body;
          if(resBody.code == '000'){
          	let sessionPhone = window.sessionStorage.getItem('phone')?window.sessionStorage.getItem('phone'):'';
          	let sessionChannel = sessionStorage.getItem('channel')?sessionStorage.getItem('channel'):'';
            window.localStorage.clear();
            window.sessionStorage.clear();
            window.sessionStorage.setItem('phone',sessionPhone);
            this.$router.push({path:'/main/home?channel='+sessionChannel});
          }else if(resBody.code == '444'){
            this.$router.push({path:'/login',query:{history:1}});
          }else{
            MessageBox.alert(resBody.mesg, '提示');
          }
        })
    },
    // 点击栏目，跳转到相应的页面{修改密码，关于我们，去反馈}
    goPage(url) {
      this.$router.push({ path: url });
    }
  },
  components: { Top }
}
</script>
<style lang="scss">
@import '../scss/variable/base.scss';
.setting {
  margin-top: 1.2rem;
  &-item {
    display: flex;
    height: 1.33rem;
    background: #fff;
    line-height: 1.33rem;
    border-bottom: 1px solid $borderColor;
    &:active {
      background: $activeColor;
    }
    &:nth-of-type(4) {
      border-bottom: none;
    }
    span {
      flex: 2;
      img {
        width: 0.5rem;
        height: 0.5rem;
        margin-top: 0.4rem;
      }
    }
    div {
      flex: 8;
      text-align: left;
      font-size: 0.4rem;
    }
    i {
      flex: 2;
      text-align: center;
    }
  }
  &-outlogin {
    width: 100%;
    height: 1.33rem;
    background: #fff;
    margin-top: 0.4rem;
    line-height: 1.33rem;
    font-size: 0.4rem;
    color: $primaryColor;
    &:active {
      background: $activeColor;
    }
  }
}
</style>
